<?php $this->load->view('layout/header');?>
<div class="container-fluid">
    <div class="row-fluid">
        <div class="span12">
            <h3 class="page-title">景区管理<small> 景区列表</small></h3>
            <?php echo breadcrumb(array('景区管理', '景区列表')); ?>
        </div>
    </div>
    <?php echo execute_alert_message() ?>
    <div class="row-fluid">
        <div class="span12">
            <div class="portlet box green">
                <div class="portlet-title">
                    <div class="caption"><i class="icon-search"></i>搜索</div>
                    <div class="tools">
                        <a class="collapse" href="javascript:;"></a>
                        <a class="remove" href="javascript:;"></a>
                    </div>
                </div>
                <div class="portlet-body form">
                    <form class="form-horizontal form-search" action="<?php echo base_url('scenery/index') ?>" method="get">
                        <div class="row-fluid">
                            <div class="span4">
                                <div class="control-group">
                                    <label class="control-label">景区名称</label>
                                    <div class="controls">
                                        <input type="text" name="scenery_search" value="<?php echo $this->input->get('scenery_search');?>" class="m-wrap span12" placeholder="请输入景区编号或景区名称">
                                    </div>
                                </div>
                            </div>
                            <div class="span4">
                                <div class="control-group">
                                    <label class="control-label">供应商</label>
                                    <div class="controls">
                                        <input type="text" name="username" value="<?php echo $this->input->get('username');?>" class="m-wrap span12" placeholder="请输入供应商帐号或别名">
                                    </div>
                                </div>
                            </div>
                            <div class="span4">
                                <div class="control-group">
                                    <label class="control-label">景区星级</label>
                                    <div class="controls">
                                        <select name="star_rank" class="m-wrap span12">
                                        <option value="">请选择</option>
                                        <?php for ($i=5; $i>=1; $i--) :?>
                                            <option value="<?php echo $i;?>" <?php if ($i == $this->input->get('star_rank')) :?> selected="selected"<?php endif;?>><?php echo $i;?>A 级景区</option>
                                        <?php endfor;?>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row-fluid">
                            <div class="span4">
                                <div class="control-group">
                                    <label class="control-label">旅游主题</label>
                                    <div class="controls">
                                        <select name="category_id" class="m-wrap span12">
                                            <option value="">请选择</option>
                                            <?php foreach ($category as $k=>$v) :?>
                                            <option value="<?php echo $k?>" <?php if ($this->input->get('category_id') == $k):?>selected="selected"<?php endif;?>><?php echo $v['category_name']?></option>
                                            <?php endforeach;?>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="span4">
                                <div class="control-group">
                                    <label class="control-label">上下架</label>
                                    <div class="controls">
                                        <select name="bit_state" class="m-wrap span12">
                                            <option value="">请选择</option>
                                            <option value="1" <?php if ($this->input->get('bit_state') === '1'):?>selected="selected"<?php endif;?>>上架</option>
                                            <option value="0" <?php if ($this->input->get('bit_state') === '0'):?>selected="selected"<?php endif;?>>下架</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="span4">
                                <div class="control-group">
                                    <label class="control-label">位置推荐</label>
                                    <div class="controls">
                                        <select name="flag_1" class="m-wrap span12">
                                            <option value="">请选择</option>
                                            <?php foreach ($flag_1 as $kk=>$vv) :?>
                                            <option value="<?php echo $kk;?>" <?php if ($this->input->get('flag_1') === (string)$kk):?> selected="selected"<?php endif;?>><?php echo $vv;?></option>
                                            <?php endforeach;?>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row-fluid">
                            <div class="span8">
                                <div class="control-group">
                                    <label class="control-label">选择省份</label>
                                    <div class="controls">
                                        <?php $this->load->view('commonhtml/districtSelect');?>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-actions">
                            <button class="btn green" type="submit">搜索</button>
                            <button class="btn reset_button_search" type="button">重置条件</button>
                        </div>
                    </form>
                </div>
            </div>
            <div class="portlet box green">
                <div class="portlet-title">
                    <div class="caption"><i class="icon-reorder"></i>列表</div>
                    <div class="tools">
                        <a class="collapse" href="javascript:;"></a>
                        <a class="remove" href="javascript:;"></a>
                    </div>
                </div>
                <div class="portlet-body flip-scroll">
                    <div class="dataTables_wrapper form-inline">
                        <div class="clearfix">
                            <a href="<?php echo base_url('scenery/add') ?>" class="add-button-link">
                                <div class="btn-group">
                                    <button class="btn green"><i class="icon-plus"></i> 添加</button>
                                </div>
                            </a>
                        </div>
                        <?php if ($all_rows > 0) :?>
                        <table class="table table-striped table-bordered table-hover" id="sample_1">
                            <thead class="flip-content">
                                <tr>
                                    <th width="15"><input type="checkbox" class="group-checkable" data-set="#sample_1 .checkboxes"></th>
                                    <th>编号</th>
                                    <th>景区名称</th>
                                    <th>旅游主题</th>
                                    <th>供应商</th>
                                    <th>省/市/区</th>
                                    <th>位置推荐</th>
                                    <th>景区星级</th>
                                    <th>添加时间</th>
                                    <th>上下架</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php foreach ($page_list->result() as $item) : ?>
                                <tr>
                                    <td><input type="checkbox" class="checkboxes" value="1" ></td>
                                    <td><?php echo $item->sid;?></td>
                                    <td width="140">
                                        <p><?php echo $item->name_hanzi;?></p>
                                        <p><?php echo $item->name_pinyin;?></p>
                                    </td>
                                    <td><?php echo $category[$item->category_id]['category_name']?></td>
                                    <td width="110">
                                        <p><?php echo $item->user_name;?></p>
                                        <p><?php echo $item->alias_name ?></p>
                                    </td>
                                    <td>
                                        <?php echo (!empty($item->provinceid) && $item->provinceid != '-1') ? $all_region[$item->provinceid]['region_name'] : $item->provinceid;?>
                                        <?php echo (!empty($item->cityid) && $item->cityid != '-11') ? '/'.$all_region[$item->cityid]['region_name'] : $item->cityid;?>
                                        <?php echo (!empty($item->areaid) && $item->areaid != '-22') ? '/'.$all_region[$item->areaid]['region_name'] : $item->areaid;?>
                                    </td>
                                    <td><?php echo isset($flag_1[$item->flag_1]) ? $flag_1[$item->flag_1] : '其它';?></td>
                                    <td><?php echo $item->star_rank;?></td>
                                    <td><?php echo date('Y-m-d H:i:s', $item->add_time);?></td>
                                    <td>
                                        <a href="javascript:;"  sid="<?php echo $item->sid?>" bit-state="<?php echo $item->bit_state;?>" class="modify-goods-bitopt glyphicons no-js <?php if ($item->bit_state==1):?>ok_2<?php else : ?>remove_2<?php endif;?>">
                                            <i></i>
                                        </a>
                                    </td>
                                    <td width="145">
                                        <a class="btn mini green" href="<?php echo base_url('scenery/images/'.$item->sid); ?>"> 图片管理</a>
                                        <a class="btn mini green" href="<?php echo base_url('goodsbase/index?sid='.$item->sid); ?>"> 门票列表</a><p></p>
                                        <a class="btn mini green" href="<?php echo base_url('scenery/edit/'.$item->sid); ?>"><i class="icon-edit"></i> 编辑</a>
                                        <a target="_blank" class="btn mini green" href="<?php echo $this->config->jingqu_url.'scenic/info/'.$item->sid.'.html'; ?>"> 预览</a>
                                    </td>
                                </tr>
                                <?php endforeach;?>
                            </tbody>
                        </table>
                        <div class="row-fluid">
                            <div class="dataTables_info">
                                <span>当前第</span><span style="color: red"><?php echo $pg_now?></span>页 
                                <span>共</span><span style="color: red"><?php echo $all_rows?></span>条数据
                                <span>每页显示20条 </span>
                                <?php echo $pg_list ?>
                            </div>
                        </div>
                        <?php else: ?>
                            <div class="alert"><p>未找到数据。<p></div>
                        <?php endif ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $this->load->view('layout/footer');?>
<script type="text/javascript">
$(function(){
    $('.modify-goods-bitopt').click(function(){
        var status = '下架';
        if ($(this).hasClass('remove_2')) {
            status = '上架';
        }
        if (confirm('确定要'+status+'?')) {
            var obj = $(this);
            var sid = $(this).attr('sid');
            var bit_state = $(this).attr('bit-state');
            $.ajax({
                url: hostUrl()+'/scenery/toggle',
                type:'POST',
                dataType:'json',
                data: {sid:sid,bit_state:bit_state},
                success: function(data) {
                    if (data.flag == 0) { //下架
                        obj.attr('bit-state', data.messages).addClass('remove_2').removeClass('ok_2');
                    } else if(data.flag == 1) { //上架
                        obj.attr('bit-state', data.messages).addClass('ok_2').removeClass('remove_2');
                    } else {
                        alert(data.messages);
                    }
                }
            });
        }
    });
});
</script>